home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DU Projects / Windoid / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-22  |  4.6 KB  |  167 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef DEFINES_K
  10. #include "Defines.k"
  11. #endif
  12.  
  13. #ifndef BINDING_K
  14. #include "Binding.k"
  15. #endif
  16.  
  17. #ifndef FRAME_H
  18. #include "Frame.h"
  19. #endif
  20.  
  21. // ----- Framework Layer -----
  22. #ifndef FWEVENT_H
  23. #include "FWEvent.h"            // FW_CMouseEvent
  24. #endif
  25.  
  26. // ----- Graphic Includes -----
  27. #ifndef FWRECT_H
  28. #include <FWRect.h>                // FW_CRect
  29. #endif
  30.  
  31. #ifndef FWRECSHP_H
  32. #include "FWRecShp.h"            // FW_CRectShape
  33. #endif
  34.  
  35. #ifndef FWPICSHP_H
  36. #include "FWPicShp.h"            // FW_PPicture, FW_CPictureShape
  37. #endif
  38.  
  39. #ifndef FWCONTXT_H
  40. #include "FWContxt.h"            // FW_CViewContext
  41. #endif
  42.  
  43. //=============================================================================
  44. #ifdef FW_BUILD_MAC
  45. #pragma segment Windoid
  46. #endif
  47.  
  48. FW_DEFINE_AUTO(CMainFrame)
  49. //=============================================================================
  50. CMainFrame::CMainFrame(Environment* ev, ODFrame* odFrame, 
  51.                         FW_CPresentation* presentation, CWindoidPart* part)
  52.   : FW_CFrame(ev, odFrame, presentation, part)
  53. {
  54.     FW_Boolean showPalette = this->IsRoot(ev);
  55.     part->MyMakePalette(ev, showPalette);
  56.     FW_END_CONSTRUCTOR
  57. }
  58.  
  59. //------------------------------------------------------------------------------
  60. CMainFrame::~CMainFrame()
  61. {
  62.     FW_START_DESTRUCTOR
  63. }
  64.  
  65. //------------------------------------------------------------------------------
  66. void 
  67. CMainFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  68. {
  69.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  70.     FW_CRect box = this->GetBounds(ev);    
  71.     FW_CRectShape::RenderRect(context, box, FW_kFill, FW_kRGBGreen);
  72. }
  73.  
  74. //=============================================================================
  75. const short kNumberOfColumns     = 6;
  76. const short kNumberOfRows         = 1;
  77. const FW_Fixed kCellSizeV     = FW_IntToFixed(42);
  78. const FW_Fixed kCellSizeH     = FW_IntToFixed(41);
  79.  
  80. FW_DEFINE_AUTO(CPaletteFrame)
  81.  
  82. //------------------------------------------------------------------------------
  83. CPaletteFrame::CPaletteFrame(Environment* ev, ODFrame* odFrame, 
  84.                             FW_CPresentation* presentation, CWindoidPart* part)
  85.   : FW_CFrame(ev, odFrame, presentation, part),
  86.     fWindoidPart(part),
  87.     fSelectedRow(0),
  88.     fSelectedCol(0)
  89. {
  90.     this->SetCanBeActiveFrame(ev, false);
  91.     FW_END_CONSTRUCTOR
  92. }
  93.  
  94. //------------------------------------------------------------------------------
  95. CPaletteFrame::~CPaletteFrame()
  96. {
  97.     FW_START_DESTRUCTOR
  98. }
  99.  
  100. //------------------------------------------------------------------------------
  101. void 
  102. CPaletteFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  103. {
  104.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  105.     FW_CRect box = this->GetBounds(ev);    
  106.  
  107.     // Draw Picture that looks like a list of Icons
  108.     FW_PSharedLibraryResourceFile resFile(ev);
  109.     FW_CPicture pict(resFile, kPalettePictID);
  110.     FW_CPictureShape shape(pict, box);
  111.     shape.Render(context);
  112.     
  113.     // Indicate "selected" Icon
  114.     FW_CRect rect;
  115.     this->GetCellRectangle(fSelectedRow, fSelectedCol, rect);
  116.     FW_CRectShape rectShape(rect, FW_kFrame);
  117.     rectShape.Render(context);
  118. }
  119.  
  120. //------------------------------------------------------------------------------
  121. FW_Handled 
  122. CPaletteFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  123. {    
  124.     // Get the mouse in local coordinates
  125.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  126.     
  127.     // See what cell was hit and store in frame
  128.     if (this->FindCell(where, fSelectedRow, fSelectedCol)) {
  129.         FW_CRect frameRect = this->GetBounds(ev);    
  130.         this->Invalidate(ev, frameRect);    
  131.     }
  132.     return true;                // we handled event
  133. }
  134.  
  135. //------------------------------------------------------------------------------
  136. FW_Boolean 
  137. CPaletteFrame::FindCell(const FW_CPoint& where, unsigned short& row, 
  138.                                                 unsigned short& column) const
  139. {
  140.     // Iterate over rows and columns and see if a cell was hit
  141.     FW_CRect rect;
  142.     for (unsigned short x = 0; x < kNumberOfColumns; x++)
  143.         for (unsigned short y = 0; y < kNumberOfRows; y++)
  144.         {
  145.             // calculate geometry of this grid cell
  146.             this->GetCellRectangle(y, x, rect);
  147.             if (rect.Contains(where))
  148.             {
  149.                 // got one
  150.                 column = x;
  151.                 row = y;
  152.                 return TRUE;
  153.             }
  154.         }
  155.     
  156.     return FALSE;
  157. }
  158. //------------------------------------------------------------------------------
  159. void 
  160. CPaletteFrame::GetCellRectangle(unsigned short row, unsigned short column, 
  161.                                                         FW_CRect& rect) const
  162. {
  163.     // Get geometry of a cell in a grid
  164.     rect.Set(FW_IntToFixed(0),FW_IntToFixed(0), kCellSizeH, kCellSizeV);
  165.     rect.Place(kCellSizeH * FW_IntToFixed(column), kCellSizeV * FW_IntToFixed(row) );
  166. }
  167.